<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div>
      <h1>类的继承</h1>
      <p>1.关键词:extends</p>
      <p>2.super关键字,始终指向父类,调用它就是调用父类的构造函数</p>
    </div>
    <script>
      class Person {
        constructor(name) {
          this.name = name;
        }
        say() {
          console.log(this.name);
          return this.name;
        }
      }

      //继承
      class Student extends Person {
        constructor(name, number) {
          //super关键字始终指向父类,调用它就调用了父类的构造函数
          super(name);
          this.number = number;
        }
        hello() {
          // 可以通过super方法调用父类的实例方法
          super.say(); //xjq
          console.log(this.number); //15
        }
      }
      const s = new Student("xjq", 15);
      s.hello();
    </script>
  </body>
</html>
